<template>
  <div>
    <div>
      <div class="content">
        <p>
          收货人 ：
          <input type="text" placeholder="请输入姓名" v-model="editInformation.receiverName" />
        </p>
        <p>
          手机号 ：
          <input type="text" placeholder="请输入手机号" v-model="editInformation.receiverMobile" />
        </p>
        <p>
          详细地址:
          <input type="text" placeholder="输入详细地址" v-model="deltailAddr" />
        </p>
      </div>

      <b></b>
      <div class="sure" @click="editAdd()">确定</div>
    </div>
		
  </div>
</template>

<script>
import { Message } from 'element-ui'
import { editAdd } from '../../api'
export default {
  data() {
    return {
      information: {
        title: '新增收货地址',
        name: '',
        phone: '',
        address: '',
      },
      editInformation: {},
      deltailAddr: '',
    }
  },

  methods: {
    editAdd() {

		let str = this.huoqu();
		console.log("----->",str);
		let end1 = str.lastIndexOf('省') + 1;
		let end2 = str.lastIndexOf('市') + 1;
		let end3 = str.lastIndexOf('区') + 1;
		// let endStringPosition = equipmentImgUrl.lastIndexOf('.');
		let province = str.substring(0, end1);
		let city = str.substring(end1,end2);
		let area = str.substring(end2,end3);
		let addr = str.substring(end3)
	

		console.log("===>",province);
		console.log("city",city);
		console.log("area",area);
		console.log("addr",addr);
      editAdd({
				addr:addr,
        addrId: this.editInformation.addrId,
        userId: this.$store.state.uid,
				 area:area,
				  city:city,
					province:province,
					 receiverMobile:this.editInformation.receiverMobile,
					  receiverName:this.editInformation.receiverName,
						  status:this.editInformation.status,
      }).then(res => {
        console.log(res, 'edit')
        this.editInformation = res.data.data
				if(res.data.code === 10000){
						console.log("修改成功！！");
       Message({
        message: "修改成功",
        type: "success",
        duration: 2500
      })
			this.$router.push('/address')
				}else{
					  Message({
        message: "修改失败",
        type: "error",
        duration: 2500
      })
				}
		
			
      })
    },
		huoqu(){
			let str = this.deltailAddr;
			return str;	
		}
  },
  mounted() {
    console.log(this.$route.params, 'aaa')

    this.$store.commit('setAddrText', this.$route.params)
    console.log(this.$store.state.addrText, 'bbb')
    this.editInformation = { ...this.$store.state.addrText }
    this.deltailAddr =
      this.editInformation.province +
      this.editInformation.city +
      this.editInformation.area +
      this.editInformation.addr
    // console.log(	this.editInformation,"heng");
		// this.editAdd()
  },
	
}
</script>

<style scoped>
.content {
  width: 100vw;
  height: 50vh;
  /* background: pink; */
  font-size: 2.5vh;
}
p {
  border-bottom: 1px solid #eee;
  margin-left: 7vw;
}

input {
  width: 60vw;
  height: 5vh;
  outline: none;
  border: none;
  margin-top: 3vh;
}
.el-cascader {
  margin-top: 3vh;
}
.sure {
  width: 100vw;
  height: 10vh;
  background: #409eff;
  position: fixed;
  bottom: 0;
  text-align: center;
  line-height: 10vh;
  font-size: 20px;
  color: #fff;
}
</style>